const path = require('path')
const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    mode: 'none',
    entry: './src/main.js',
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'js/bundle.[hash:6].js' // 设置hash值 并将文件放置在dist/js下        
    },
    module: {
        rules: [{
                test: /\.vue$/,
                use: 'vue-loader'
            },
            {
                test: /\.css$/,
                use: [ // use多个从后往前执行   先用到的放后面
                    'style-loader',
                    'css-loader'
                ]
            },
            {
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader']
            },
            {
                test: /\.(png|jpe?g|gif)$/,
                use: {
                    loader: 'url-loader', // 适合小文件 将文件转化为 base64 
                    // 符合规则就转 不能转就使用 fallback => file-loader
                    options: {
                        name: "img/[name].[contenthash:6].[ext]",
                        limit: 8 * 1024, // KB 设置限制  超过则使用file-loader
                        esModule: false
                    }
                }
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            title: 'Webpack Vue',
            favicon: path.resolve(__dirname, 'public/favicon.ico'),
            template: path.join(__dirname, 'public/index.html')
        }),
        new webpack.DefinePlugin({ // 默认值配置
            BASE_URL: '"/"'
        })
    ]
}